package com.sam.interceptor;

import java.util.Map;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

public class AuthenticationInterceptor implements Interceptor {

	private static final long serialVersionUID = 2719410972136709042L;

	public void destroy() {
	  }

	  public void init() {
	  }

	  public String intercept(ActionInvocation actionInvocation) throws Exception {
	    Map<String, Object> session = actionInvocation.getInvocationContext().getSession();
	    
	    if (!(actionInvocation.getProxy().getActionName().equalsIgnoreCase("login")) && 
	    	!(actionInvocation.getProxy().getActionName().equalsIgnoreCase("reporteCall")) &&
	    	!(actionInvocation.getProxy().getActionName().equalsIgnoreCase("reportePacientes")) &&
	    	!(actionInvocation.getProxy().getActionName().equalsIgnoreCase("concurrio")) &&
	    	!(actionInvocation.getProxy().getActionName().equalsIgnoreCase("obtenerAnalistas")) &&
	    	!(actionInvocation.getProxy().getActionName().equalsIgnoreCase("obtenerMarkers")) &&
	    	!(actionInvocation.getProxy().getActionName().equalsIgnoreCase("guardarDatos")) &&
	    	session.get("usuario") == null) {
	      return "login";
	    } else {
	      return actionInvocation.invoke();
	    }
	  }
}